
const html = $('html');
const themeButton = $('#theme-switch');

$(document).ready(function () {

  const a = window.matchMedia("(prefers-color-scheme: dark)");
  console.log(a.matches);
  themeSwitch();
  'use strict';
  // ========================
  // For Fade-in effect
  // ========================

  $('html').removeClass('fade-out');

  // =================
  // Responsive videos
  // =================

  $('.post-content').fitVids({
    'customSelector': ['iframe[src*="ted.com"]']
  });

  // ===============
  // Off Canvas menu
  // ===============

  $('.off-canvas-toggle').click(function (e) {
    e.preventDefault();
    $('.off-canvas-container').toggleClass('is-active');
  });


});



function toggleNightMode() {
  if (html.attr('data-theme') === 'light') {
    html.attr('data-theme', 'dark');
    themeButton.addClass('active');
    sessionStorage.setItem("theme", "dark");
  } else {
    html.attr('data-theme', 'light');
    themeButton.removeClass('active');
    sessionStorage.setItem("theme", "light");
  }
}

function themeSwitch() {
  let sessionTheme = sessionStorage.getItem('theme');
  if (sessionTheme === 'dark' || (!('theme' in sessionStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
    html.attr('data-theme', 'dark');
    $('#theme-switch').addClass('active');
  }
}
